home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
3D Game Programming All in One
/
3D Game Programming All in One Disc.iso
/
3D2E
/
RESOURCES
/
KOOB
/
control
/
server
/
vehicles
/
car.cs
Wrap
Text File
|
2006-09-24
|
7KB
|
230 lines
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Information extacted from the shape.
//
// Wheel Sequences
// spring# Wheel spring motion: time 0 = wheel fully extended,
// the hub must be displaced, but not directly animated
// as it will be rotated in code.
// Other Sequences
// steering Wheel steering: time 0 = full right, 0.5 = center
// breakLight Break light, time 0 = off, 1 = breaking
//
// Wheel Nodes
// hub# Wheel hub, the hub must be in it's upper position
// from which the springs are mounted.
//
// The steering and animation sequences are optional.
// The center of the shape acts as the center of mass for the car.
//-----------------------------------------------------------------------------
datablock AudioProfile(CarSoftImpactSound)
{
filename = "~/data/sound/vcrunch.ogg";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(CarHardImpactSound)
{
filename = "~/data/sound/vcrash.ogg";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(CarWheelImpactSound)
{
filename = "~/data/sound/impact.ogg";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(CarThrustSound)
{
filename = "~/data/sound/caraccel.ogg";
description = AudioDefaultLooping3d;
preload = true;
};
datablock AudioProfile(CarEngineSound)
{
filename = "~/data/sound/caridle.ogg";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(CarSquealSound)
{
filename = "~/data/sound/squeal.ogg";
description = AudioClose3d;
preload = true;
};
datablock ParticleData(TireParticle)
{
textureName = "~/data/particles/dustParticle";
dragCoefficient = 2.0;
gravityCoefficient = -0.1;
inheritedVelFactor = 0.1;
constantAcceleration = 0.0;
lifetimeMS = 1000;
lifetimeVarianceMS = 0;
colors[0] = "0.46 0.36 0.26 1.0";
colors[1] = "0.46 0.46 0.36 0.0";
sizes[0] = 0.50;
sizes[1] = 1.0;
};
datablock ParticleEmitterData(TireEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 0;
ejectionVelocity = 1;
velocityVariance = 1.0;
ejectionOffset = 0.0;
thetaMin = 5;
thetaMax = 20;
phiReferenceVel = 0;
phiVariance = 360;
overrideAdvance = false;
particles = "TireParticle";
};
//----------------------------------------------------------------------------
datablock WheeledVehicleTire(DefaultCarTire)
{
// Tires act as springs and generate lateral and longitudinal
// forces to move the vehicle. These distortion/spring forces
// are what convert wheel angular velocity into forces that
// act on the rigid body.
shapeFile = "~/data/models/vehicles/wheel.dts";
staticFriction = 4;
kineticFriction = 1.25;
// Spring that generates lateral tire forces
lateralForce = 18000;
lateralDamping = 4000;
lateralRelaxation = 1;
// Spring that generates longitudinal tire forces
longitudinalForce = 18000;
longitudinalDamping = 4000;
longitudinalRelaxation = 1;
};
datablock WheeledVehicleSpring(DefaultCarSpring)
{
// Wheel suspension properties
length = 0.85; // Suspension travel
force = 3000; // Spring force
damping = 600; // Spring damping
antiSwayForce = 3; // Lateral anti-sway force
};
//-----------------------------------------------------------------------------
function WheeledVehicleData::create(%block)
{
%obj = new WheeledVehicle() {
dataBlock = %block;
mountable = true;
};
return(%obj);
}
//-----------------------------------------------------------------------------
function WheeledVehicleData::onAdd(%this,%obj)
{
// Setup the car with some defaults tires & springs
for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
%obj.setWheelTire(%i,DefaultCarTire);
%obj.setWheelSpring(%i,DefaultCarSpring);
%obj.setWheelPowered(%i,false);
}
// Steer front tires
%obj.setWheelSteering(0,1);
%obj.setWheelSteering(1,1);
// Only power the two rear wheels...
%obj.setWheelPowered(2,true);
%obj.setWheelPowered(3,true);
}
function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
}
datablock WheeledVehicleData(DefaultCar)
{
category = "Vehicles";
className = "Car";
shapeFile = "~/data/models/vehicles/runabout.dts";
emap = true;
maxDamage = 1.0;
destroyedLevel = 0.5;
maxSteeringAngle = 0.785; // Maximum steering angle
tireEmitter = TireEmitter; // All the tires use the same dust emitter
// 3rd person camera settings
cameraRoll = true; // Roll the camera with the vehicle
cameraMaxDist = 6; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.1; // Velocity lag of camera
cameraDecay = 0.75; // Decay per sec. rate of velocity lag
// Rigid Body
mass = 200;
massCenter = "0 -0.5 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 4; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance
// Engine
engineTorque = 4000; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 30; // Engine scale by current speed / max speed
// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;
// Sounds
engineSound = CarEngineSound;
jetSound = CarThrustSound;
squealSound = CarSquealSound;
softImpactSound = CarSoftImpactSound;
hardImpactSound = CarHardImpactSound;
wheelImpactSound = CarWheelImpactSound;
mountPose[0] = "sitting";///***KCF***24/09/2006 11:53PM
mountPose[1] = "sitting";///***KCF***24/09/2006 11:53PM
numMountPoints = 2;///***KCF***24/09/2006 11:53PM
};